package com.zhuqieli.database_learn.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zhuqieli.database_learn.pojo.FileTable;
import com.zhuqieli.database_learn.pojo.UserTable;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * @author dupr
 * @description 文件mapper
 * @date 2023/8/30 19:54:37
 */
@Mapper
public interface FileTableMapper extends BaseMapper<FileTable> {
    @Select("SELECT file_name FROM file_table WHERE user_id = #{userId} and snowflake_id = #{fileId}")
    String findFileNameByUserIdAndFileId(Integer userId, String fileId);

    @Select("SELECT suffix FROM file_table WHERE user_id = #{userId} and snowflake_id = #{fileId}")
    String findSuffixByUserIdAndFileId(Integer userId, String fileId);

    public List<FileTable> selectPublic(int size, int current);

    void incrementDownloadTimes(@Param("user_id") Integer userId);

    void incrementDownloadTimes(@Param("snowflake_id") String fileId);

    @Select("SELECT file_size FROM file_table WHERE user_id = #{userId} and snowflake_id = #{fileId}")
    String findFileSizeByUserIdAndFileId(Integer userId, String fileId);

}
